<%@ page language="java" pageEncoding="utf8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"
	dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="<c:url value="/css/shopadmin.css"/>"
			type="text/css" />
		<link rel="stylesheet"
			href="<c:url value='/scripts/themes/base/jquery.ui.all.css'/>"
			type="text/css" />
	</head>
	<body style="">
		<div id="headBar" class="head_content"></div>
		<div id="main" class="main_content">

			<form class="tableform" action="mt_promotion_goods_save.html" method="post" id="SelectProductForm">
				<input type="hidden" name="marketPromotion.pmtId"	value="${marketPromotion.pmtId}" />
				<div class="division">
					<table cellspacing="0" cellpadding="0" border="0" id="select_mac">
						<tbody>
							<c:if test="${marketPromotion.pmtBondType ==1}">
								<tr>
									<td>
										<input type="radio" checked="checked" name="pmt_bond_type" value="1" />
									</td>
									<td>
										选择商品
									</td>
								</tr>

							</c:if>
							<c:if test="${marketPromotion.pmtBondType == 2}">
								<tr>
									<td>
										<input type="radio" checked="checked" name="pmt_bond_type" value="2"/>
									</td>
									<td>
										全部商品
									</td>
								</tr>

							</c:if>
							<!-- <tr> <td><input type='radio' value='2' name='pmt_bond_type' /></td> <td>分类加品牌</td> </tr>-->
						</tbody>
					</table>
				</div>
				<c:if test="${marketPromotion.pmtBondType ==1}">
					<div style="" id="s_p">
						<div class="clearfix">
							<div class="object-select clearfix">
								<div onclick="openRelativeDialog()" class="label">
									请选择...
								</div>
								<div onclick="openRelativeDialog()" class="handle">
									&nbsp;
								</div>
							</div>
							<div class="gridlist rows-body" id="relative_box">
							</div>
						</div>
					</div>

				</c:if>


				<div class="table-action">
					<button class="btn" type="button"
						onclick="location.href='mt_activity_rule_edit.html?marketPromotionActivity.pmtaId=${marketPromotion.relatedId}&marketPromotionScheme.pmtsId=${marketPromotion.pmtsId}&pmtId=${marketPromotion.pmtId}'">
						<span><span>上一步</span> </span>
					</button>
					<button class="btn" type="submit">
						<span><span>下一步</span> </span>
					</button>
					<button class="btn" type="button">
						<span><span>取消</span> </span>
					</button>
				</div>
			</form>
		</div>
		<div id="footBar" class="foot_content"></div>


		<div id="relative-dialog" title="商品列表">
			<div id="search-tab">
				<div id="selector-panel-form">
					<div id=" ">
						<div class="gridlist">
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										分类
									</div>
									<div class="span-3">
										是&nbsp;
									</div>
									<div class="span-6">
										<div class="object-select clearfix">
											<select class="x-input" id="search_catId"
												name="goodsSelectParameter.catId">
												<option value="">
													请选择
												</option>
												<c:forEach var="list" items="${goodsCats}"
													varStatus="status1">
													<option value="${list.catId }">
														${list.catName }
													</option>
												</c:forEach>
											</select>
										</div>
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										品牌
									</div>
									<div class="span-3">
										是&nbsp;
									</div>
									<div class="span-6">
										<div class="object-select clearfix">
											<select name="goodsSelectParameter.brandId"
												id="search_brandId" class="x-input-select  inputstyle">
												<option value="">
													请选择
												</option>
												<c:forEach var="list" items="${goodsBrands}"
													varStatus="status1">
													<option value="${list.brandId }">
														${list.brandName }
													</option>
												</c:forEach>
											</select>

										</div>
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										销售价
									</div>
									<div class="span-3">
										<select class="x-input-select  inputstyle"
											id="search_price_selector"
											name="goodsSelectParameter.priceSelector">
											<option value="than">
												大于
											</option>
											<option value="lthan">
												小于
											</option>
											<option value="equal">
												等于
											</option>
											<option value="sthan">
												小于等于
											</option>
											<option value="bthan">
												大于等于
											</option>
										</select>
										&nbsp;
									</div>
									<div class="span-6">
										<input class="x-input" name="goodsSelectParameter.price"
											id="search_price" value="" type="text" />
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										货号
									</div>
									<div class="span-3">
										&nbsp;
									</div>
									<div class="span-6">
										<input class="x-input " name="goodsSelectParameter.bn"
											type="text" id="search_bn" />
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										商品名称
									</div>
									<div class="span-3">

										&nbsp;
									</div>
									<div class="span-6">
										<input class="x-input " name="goodsSelectParameter.name"
											type="text" id="search_name" />
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										上架
									</div>
									<div class="span-3">
										&nbsp;
									</div>
									<div class="span-6">

										<select class="x-input-select  inputstyle"
											name="goodsSelectParameter.marketOn" id="search_marketOn">
											<option value="">
												无
											</option>
											<option value="true">
												上架
											</option>
											<option value="false">
												下架
											</option>

										</select>
										&nbsp;
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>
							<div class="row">
								<div class="row-line">
									<div class="span-3">
										库存
									</div>
									<div class="span-3">
										<select class="x-input-select  inputstyle"
											name="goodsSelectParameter.storeSelector"
											id="search_store_selector">
											<option value="than">
												大于
											</option>
											<option value="lthan">
												小于
											</option>
											<option value="equal">
												等于
											</option>
											<option value="sthan">
												小于等于
											</option>
											<option value="bthan">
												大于等于
											</option>
										</select>
										&nbsp;
									</div>
									<div class="span-6">
										<input class="x-input " name="goodsSelectParameter.store"
											type="text" id="search_store" />
									</div>
									<div class="span-1">

									</div>
								</div>
							</div>

						</div>
					</div>
				</div>
				<div class="scrollhandle toLeft gridlist-head"
					style="text-align: left;">
					<button type="button" class="btn" onclick="searchSubmit(1)">
						<span><span>&lt;&lt;筛选并返回列表</span> </span>
					</button>
				</div>
			</div>
			<div id="search-result" style='display: none;'>
				<div class="scrollhandle toRight gridlist-head"
					style="text-align: right;">
					<button type="button" class="btn" onclick="searchTab()">
						<span><span>筛选&gt;&gt;</span> </span>
					</button>
				</div>
				<div class="gridlist selectorlist" id="selector-body">


				</div>
				<div class="dialog-content-foot">
					<div class="table-action">
						<button class="btn"
							onclick="addRow();$('#relative-dialog').dialog('close');"
							type="button">
							<span><span>确定</span> </span>
						</button>
						<button class="btn"
							onclick="searchTab();$('#relative-dialog').dialog('close');"
							type="button">
							<span><span>取消</span> </span>
						</button>
					</div>
				</div>
			</div>
		</div>
		<div id="goods-result-row-tmpl" style="display: none;">
			<div class="row">
				<div class="row-line">
					<input name="selected_rate_goods" vname="#name#" value="#goodsId#"
						type="checkbox" />
					<label for="edit_sel__0">
						#name#
					</label>
				</div>
			</div>
		</div>
		<div id="goods-row-tmpl" style="display: none;">
			<div class="row">
				<div class="row-line">
					<div class="span-1">
						<span class="opt"><img
								style="width: 16px; height: 16px; background-position: 0pt -214px;"
								class="imgbundle" onclick="deleteGoodsRateRow(this,#_pgId#)"
								src="<c:url value="/images/transparent.gif"/>" /> </span>
					</div>
					<div class="span-auto  ">
						<input type="hidden" value="#pgId#"
							name="marketPromotionGoodss[#index#].pgId" />
						<input type="hidden" value="#goodsId#"
							name="marketPromotionGoodss[#index#].goodsId" />
						#name#
					</div>
				</div>
			</div>
		</div>


		<script type="text/javascript"
			src="<c:url value='/scripts/jquery-1.4.2.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/jquery.bgiframe-2.1.1.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.core.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.widget.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.mouse.js'/> "></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.button.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.draggable.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.position.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.ui.dialog.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/ui/jquery.effects.core.js'/> "></script>
		<script type="text/javascript">
 
	String.prototype.replaceAll = function(s1, s2) {
			return this.replace(new RegExp(s1, "gm"), s2);
	}
 
	
	//goods rate begin
		function searchSubmit(page_id){
			var url = "gd_goods_jsonSearch.html";			
			
			var params = {
				"pagerId"  		:	page_id,
				"goodsSelectParameter.catId"    		: 	$('#search_catId').val(),
				"goodsSelectParameter.brandId" 		: 	$('#search_brandId').val(),
				"goodsSelectParameter.priceSelector" : $('#search_price_selector').val(),
				"goodsSelectParameter.price" : $('#search_price').val(),
				"goodsSelectParameter.bn" : $('#search_bn').val(),
				"goodsSelectParameter.name" : $('#search_name').val(),
				"goodsSelectParameter.storeSelector" : $('#search_store_selector').val(),
				"goodsSelectParameter.store" : $('#search_store').val(),
				"goodsSelectParameter.marketOn"    :  $('#search_marketOn').val()
			};

			$.post(url, params, 
				function callback(data) 
				{	
					var goodss = data.goodss;
					$('#selector-body').html('');
					$.each( goodss, function(i, n){  				
					
		  				var tmpl = $('#goods-result-row-tmpl').html();
						tmpl = tmpl.replaceAll('#name#', goodss[i].name);	
						tmpl = tmpl.replaceAll('#goodsId#', goodss[i].goodsId);
						$('#selector-body').append(tmpl);
  							
  					});
  					var pagerStr = data.pagerString;
  					$('<div class="gridlist-footer" >'+pagerStr +'</div>').appendTo('#selector-body');
				},
				"json"
			);
			
			$('#search-tab').css("display","none");
			$('#search-result').css("display","");
			
		
		}
		
		function deleteGoodsRateRow(clickObj,pgId){
			if(!confirm('<fmt:message key="common.confirm_deleted" />')){
				return;
			}
			if(pgId=='' || pgId!=0){
				deleteGoodsRate(pgId);
			}
			$(clickObj).parent().parent().parent().remove(); 
		}
		
		function deleteGoodsRate(pgId){
			var url = "mt_promotion_goods_delete.html";
			var params = {
				"pgId"  		:	pgId

			};

			$.getJSON(url, params, 
				function callback(data) 
				{	
					alert("删除成功");
				}
			);
			
			 
			
		
		}
		
		
		function searchTab(){
			$('#search-tab').css("display","");
			$('#search-result').css("display","none");
		}
		var mpgIndex = 0;		
		function addRow(){
								
			var existedRate = $("#relative_box >div >div >div > input:hidden");			
			$("input[name='selected_rate_goods']").each(function(index, domEle) {
				if($(domEle).attr("checked")){
					var bool =true;
					existedRate.each(function(ind, dome){
						if($(domEle).val()==$(dome).val()){
							bool = false;
							return;
						}					
					});
					if(bool){  						
  						addTmplRow($(domEle).attr("vname"),$(domEle).val(),0);
					}
					
				} 
			});
			
			// init back
			searchTab();
			$('#selector-body').html('');
			
		}
		
		
		function addTmplRow(name,goodsId,pgId){
				var _pgId =pgId;
				if(pgId==0){
					//在服务器端保证不存在marketPromotionGoods.pgId为0的数据
					pgId = '';					
				}
				var tmpl = $('#goods-row-tmpl').html();
				tmpl = tmpl.replaceAll('#name#', name);	
				tmpl = tmpl.replaceAll('#goodsId#', goodsId);
				tmpl = tmpl.replaceAll('#pgId#', pgId);
				tmpl = tmpl.replaceAll('#_pgId#', _pgId);
				tmpl = tmpl.replaceAll('#index#', mpgIndex);
				$('#relative_box').append(tmpl);
  				mpgIndex++;		
		}
		
		<c:forEach var="mpg" items="${marketPromotionGoodss}"	>
			addTmplRow( '${mpg.goodsName}' ,${mpg.goodsId},${mpg.pgId});
		</c:forEach>
		
		
		$(function() {	
			
        	$("#relative-dialog").dialog({
				autoOpen: false,
				height: 350,
				width: 550,
				modal: true,
				close: function() {
					searchTab();
					$('#selector-body').html('');
				}
			});
        });
        function openRelativeDialog(){		 	
			$('#relative-dialog').dialog('open');
		}
		//goods rate end
</script>

	</body>
</html>